<template>
	<view class="contont">
		<nav-bar :title="title" :iconLeft="true" />
		<view class="content-bgc">
			<view class="b-con">
				<up-cell-group :border="false">
					<up-cell title="生产入库单号">
						<template #value>
							<view class="cell-text">{{ detail_record.code }} </view>
						</template>
					</up-cell>
					<up-cell title="生产单号">
						<template #value>
							<view class="cell-text">{{ detail_record.order_code }} </view>
						</template>
					</up-cell>
					<up-cell title="备注">
						<template #value>
							<view class="cell-text" style="width: 70%;">{{ detail_record.desc }}</view>
						</template>
					</up-cell>
				</up-cell-group>
			</view>
			<view class="b-con">
				<up-cell-group :border="false">
					<up-cell :isLink="true" :border="false" :title="`产品：总数量（${car_list.length}）`" @click="car_popupShow = true">
						<template #value>
							<view class="cell-text">点击查看 </view>
						</template>
					</up-cell>
				</up-cell-group>
			</view>
			<custom-popup :popupShow="car_popupShow" mode="bottom" :title="'生产'" @close="car_popupShow = false" height="70vh">
				<z-paging v-if="car_popupShow" ref="paging_car" :refresher-enabled="false" :loading-more-enabled="false" :fixed="false" v-model="car_list"
					@query="queryList_car">
					<uni-card v-for="(item, index) in car_list" :key="index" margin="5px" spacing="0" :title="item.name"
						:sub-title="item.code">
						<view>名称：{{ item.name }}</view>
						<view class="ctent">编号：{{ item.code }}</view>
						<view class="ctent">规格：{{ item.specification }}</view>
						<view class="con">
							<view class="ctent">基本单位：{{ item.unit_main }}</view>
							<view class="ctent">数量：{{ item.num }}</view>
						</view>
						<view class="con">
							<view class="ctent">已完成数量：{{ item.finish_num }}</view>
							<view class="ctent">已入库数量：{{ item.up_num }}</view>
						</view>
						<view class="ctent">入库仓库：{{ item.warehouse_name }}</view>
						<view class="ctent">本期入库数量：{{ item.now_num }}</view>
					</uni-card>
				</z-paging>
			</custom-popup>
		</view>
	</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import pInApi from '../../../api/production/p_in'

const detail_record = ref({})
const title = '生产入库详情';
onLoad(option => {
	get_detail(option.id);
})

const car_popupShow = ref(false);
const car_list = ref([]);
function get_detail(id) {
	pInApi.production_in_detail(id).then(data => {
		detail_record.value = data
		pInApi.get_production_in_product({ order_in__id: data.id }).then(res2 => {
			car_list.value = res2.results.map(v => {
				return {
					id: v.order_product.product.id,
					order_product_id: v.order_product.id,
					code: v.order_product.product.code,
					name: v.order_product.product.name,
					specification: v.order_product.product.specification,
					unit_main: v.order_product.product.unit_main,
					num: v.num,
					finish_num: v.finish_num,
					up_num: v.up_num,
					now_num: v.now_num,
					warehouse_name: v.order_product.product.stock_info[0].warehouse_name,
				}
			})
		})
	})
}
const paging_car = ref(null);
function queryList_car() {
	paging_car.value.complete(car_list.value);
};

</script>

<style lang="scss"></style>